package com.cat.dataStructure03;

import java.util.ArrayList;
import java.util.Arrays;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/sum-in-a-matrix/
 * @create 2025/11/8 16:42
 * @since JDK17
 */

public class Solution23 {
    public int matrixSum(int[][] nums) {
        int ans = 0, n = nums.length, m = nums[0].length;
        for (int i = 0; i < n; i++) {
            Arrays.sort(nums[i]);
        }
        for (int i = m - 1; i >= 0; i--) {
            int max = Integer.MIN_VALUE;
            for (int j = 0; j < n; j++) {
                max = Math.max(max, nums[j][i]);
            }
            ans += max;
        }

        return ans;
    }
}
